﻿namespace TroubleshootingofBeanBagAssistant.lCheck
{
	public class AntivirusCheck : IDiagnosticCheck
	{
		public string Name => "杀毒软件检测";

		public CheckResult Run()
		{
			var avList = AntivirusHelper.GetAntivirusStatus();
			if (avList == null || avList.Count == 0)
			{
				return new CheckResult
				{
					Title = "未检测到杀毒软件",
					Detail = "请确保有启用的杀毒软件以保护系统安全"
				};
			}

			var sb = new System.Text.StringBuilder();
			foreach (var av in avList)
			{
				string info = $"杀毒软件名称: {av.DisplayName}, 状态: {av.ProductState}, 路径: {av.PathToExe}";
				string displayName = av.DisplayName?.ToLower() ?? "";

				if (displayName.Contains("腾讯电脑管家系统防护") ||
					displayName.Contains("windows defender") ||
					displayName.Contains("defender") ||
					displayName.Contains("360"))
				{
					sb.AppendLine($"{info}（已授权）");
				}
				else
				{
					sb.AppendLine($"{info}（可能阻止运行）");
				}
			}

			if (AntivirusHelper.HasActiveAntivirus())
			{
				return new CheckResult
				{
					Title = "检测到启用的杀毒软件",
					Detail = sb.ToString().Trim() + "\r\n请确保杀毒软件未阻止AIMouse运行"
				};
			}
			else
			{
				return new CheckResult
				{
					Title = "未检测到启用的杀毒软件",
					Detail = sb.ToString().Trim() + "\r\n请确保有启用的杀毒软件以保护系统安全"
				};
			}
		}
	}
}
